//// http://svn.boost.org/svn/boost/sandbox/SOC/2009/unicode/libs/unicode/example/base64.cpp
//// http://hamigaki.sourceforge.jp/hamigaki/iostreams/filter/base64.hpp
//// Bajar http://svn.boost.org/svn/boost/sandbox/SOC/2009/unicode
//
//
////--------------------------------------------------------------------------------
//////#include <boost/iterator/convert_iterator.hpp>
//////#include <boost/iterator/converter_concept.hpp>
//////#include <boost/iterator/converter_codecvt.hpp>
////#include <boost/range/as_literal.hpp>
//////#include <boost/iostreams/filtering_stream.hpp>
//////#include <boost/iostreams/device/file.hpp>
////#include <fstream>
////#include "base64.hpp"
////
////
////int main()
////{
////    char data_in_[] = "fooba";					// Zm9vYmE=
////    
////    boost::iterator_range<const char*> data_in = boost::as_literal(data_in_);
////    
////    std::locale old_loc;
////    std::locale b64loc(old_loc, new base64_codecvt(boost::size(data_in)));
////
////	std::cout << "proxy authentication: " << set_locale(b64loc) << data_in << set_locale(old_loc) << '\n' << "other header: " << "value";
////
////	//std::cout << "proxy authentication: ";
////	//std::cout.imbue(b64loc);
////	//std::cout << data_in;
////	//std::cout.imbue(old_loc);
////	//std::cout << "\n";
////
////
////}
//
//
//
////--------------------------------------------------------------------------------
//
//
//////#include <boost/iostreams/device/file_descriptor.hpp>
////#include <boost/iostreams/filtering_stream.hpp>
////#include <boost/iostreams/device/file.hpp>
////
////namespace io = boost::iostreams;
////
////int main()
////{   
////	io::filtering_ostream out;
////	//out.push(compressor());
////	//out.push(base64_encoder());
////	out.push( io::file_sink("my_file.txt") );
////
////	out << "hola";
////}
//
//
////--------------------------------------------------------------------------------
//
//
//// http://svn.boost.org/svn/boost/sandbox/SOC/2009/unicode/libs/unicode/example/base64.cpp
//// Bajar http://svn.boost.org/svn/boost/sandbox/SOC/2009/unicode
//
//
//#include <boost/iterator/convert_iterator.hpp>
//#include <boost/iterator/converter_codecvt.hpp>
//
//#include <boost/range/as_literal.hpp>
//
//#include <fstream>
//
//struct base64_encoder
//{
//    typedef char input_type;
//    typedef char output_type;
//    
//    typedef boost::mpl::int_<4> max_output;
//    
//    template<typename In, typename Out>
//    Out ltr(In& begin, In end, Out out)
//    {
//        const char * lookup_table = 
//            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
//            "abcdefghijklmnopqrstuvwxyz"
//            "0123456789"
//            "+/";
//        
//        char in[3];
//        
//        in[0] = *begin++;
//        *out++ = lookup_table[in[0] >> 2];
//        if(begin == end)
//        {
//            *out++ = lookup_table[(in[0] & 0x03) << 4];
//            *out++ = '=';
//            *out++ = '=';
//            return out;
//        }
//        
//        in[1] = *begin++;
//        *out++ = lookup_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
//        if(begin == end)
//        {
//            *out++ = lookup_table[(in[1] & 0x0f) << 2];
//            *out++ = '=';
//            return out;
//        }
//        
//        in[2] = *begin++;
//        *out++ = lookup_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
//        *out++ = lookup_table[in[2] & 0x3f];
//        return out;
//    }
//    
//    template<typename In, typename Out>
//    Out rtl(In begin, In& end, Out out)
//    {
//        size_t to_read = std::distance(begin, end) % 3;
//        if(!to_read)
//            to_read = 3;
//        
//        char in[3];
//        for(size_t i=0; i<to_read; i++)
//            in[to_read-i-1] = *--end;
//            
//        char* b = in;
//        return ltr(b, in+to_read, out);
//    }
//};
//
//template<std::size_t N>
//struct fixed_boundary
//{
//    typedef char input_type;
//    
//    template<typename In>
//    bool operator()(In begin, In end, In pos)
//    {
//        return !(std::distance(begin, pos) % N);
//    }
//};
//
//typedef boost::converter_codecvt<
//    char,
//    fixed_boundary<3>,
//    base64_encoder,
//    fixed_boundary<3>,
//    base64_encoder
//> base64_codecvt;
//
//#define CHECK_EQUAL(a, b) if(a != b) std::unexpected();
//
//int main()
//{
//    char data_in_[] = "fooba";
//    char data_out_[] = "Zm9vYmE=";
//    
//    boost::iterator_range<const char*> data_in = boost::as_literal(data_in_);
//    boost::iterator_range<const char*> data_out = boost::as_literal(data_out_);
//    
//    std::locale old_loc;
//    std::locale loc(old_loc, new base64_codecvt(boost::size(data_in)));
//    {
//        std::ofstream ofs("test.base64");
//        ofs << data_in;
//    }
//    
//    std::ifstream ifs("test.base64");
//    ifs.imbue(loc);
//    
//    char c;
//    size_t i = 0;
//    while(ifs.get(c))
//    {
//        CHECK_EQUAL(c, data_out[i]);
//        ++i;
//    }
//    CHECK_EQUAL(i, (size_t)boost::size(data_out));
//}
//
//
//
////--------------------------------------------------------------------------------
//
//
////Yes, it's a feature, but unfortunately the base64 logic is intertwined with the iterator logic, and concerns are not as well separated as they could be.
////
////From a glimpse at the code, I am also not really convinced that it's got maximal efficiency either, it could probably be faster by computing at compile-time the optimal bit twiddling logic and reducing the redundant branches.
////
////I have an implementation of a generic system that can generate, from a model of a very simple and explicit Converter concept, an iterator adaptor, an eager algorithm, a codecvt facet or a boost.iostreams filter.
////
////The idea is basically that I put inside a concept the notion of a conversion step, and then I built an iterator adaptor that can work for any model of that concept.
////
////A possible implementation of a base64 encoder Converter, along with a codecvt demo (hardly the best backend) is available at
////<http://svn.boost.org/svn/boost/sandbox/SOC/2009/unicode/libs/unicode/example/base64.cpp>
////
////It's not generic (in the sense that it doesn't allow N to M bit conversion like transform_width, it just does base64 -- after all it's only meant to be an example) but that's something that would also be fairly easy to do.
////
////Now I am not suggesting that Boost should definitely use this, I'm just presenting alternatives.
//
//
//
